package com.zx.mes.hyl.security.core.validate.code.sms.impl;

import com.zx.mes.hyl.security.core.properties.SecurityConstants;
import com.zx.mes.hyl.security.core.validate.code.ValidateCode;
import com.zx.mes.hyl.security.core.validate.code.impl.AbstractValidateCodeProcessor;
import com.zx.mes.hyl.security.core.validate.code.sms.SmsCodeSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * 短信验证码处理器
 * @author huayunlong
 * @date 2018-6-2
 */
@Component("smsValidateCodeProcessor")
public class SmsValidateCodeProcessor extends AbstractValidateCodeProcessor<ValidateCode> {

    @Autowired
    private SmsCodeSender smsCodeSender;


    @Override
    protected void send(ServletWebRequest request, ValidateCode validateCode) throws Exception {
        String parameter= SecurityConstants.DEFAULT_PARAMETER_NAME_MOBILE;
        String mobile= ServletRequestUtils.getRequiredStringParameter(request.getRequest(),parameter);
        smsCodeSender.send(mobile,validateCode.getCode());
    }
}
